#include "nm_event.h"


NTSTATUS kevent::Create( EVENT_TYPE Type /*= NotificationEvent*/, BOOLEAN InitialState /*= FALSE*/ )
{
	NTSTATUS ns;
	OBJECT_ATTRIBUTES oa;

	m_Event = 0;

	InitializeObjectAttributes(&oa,
		NULL,
		OBJ_KERNEL_HANDLE,
		0,
		NULL);

	ns = ZwCreateEvent(&m_Event,
		EVENT_ALL_ACCESS,
		&oa,
		Type,
		InitialState);

	return ns;
}

NTSTATUS kevent::Create( PWCHAR Name, EVENT_TYPE Type /*= NotificationEvent*/, BOOLEAN InitialState /*= FALSE*/ )
{
	NTSTATUS ns;
	OBJECT_ATTRIBUTES oa;
	UNICODE_STRING EventName;
	m_Event = 0;

	RtlInitUnicodeString(&EventName, Name);

	InitializeObjectAttributes(&oa,
		&EventName,
		OBJ_KERNEL_HANDLE,
		0,
		NULL);

	ns = ZwCreateEvent(&m_Event,
		EVENT_ALL_ACCESS,
		&oa,
		Type,
		InitialState);

	return ns;
}

NTSTATUS kevent::Wait( PLARGE_INTEGER Timeout /*= NULL*/, BOOLEAN Alertable /*= FALSE*/ )
{
	return ZwWaitForSingleObject(m_Event, Alertable, Timeout);
}
NTSTATUS kevent::Set( PLONG PreviousState )
{
	return ZwSetEvent(m_Event, PreviousState);
}